package cc.avatar.model.rule;

import org.apache.commons.lang.StringUtils;

import cc.avatar.model.AccountingEvent;
import cc.avatar.model.PostingRule;
import cc.avatar.model.Warehousing;

public class ProduceCostPR extends PostingRule {
    
	private boolean byBlock = false;
	
	private int price;
	//column,25	
	public ProduceCostPR(String parameters){
		String[] params = StringUtils.split(parameters, ",");
		this.byBlock = "block".equals(params[0]);
		this.price = Integer.valueOf(params[1]);
	}
	
	@Override
	protected double calculateAmount(AccountingEvent evt) {
		Warehousing wh = (Warehousing)evt;      
        return (byBlock?wh.getQuantityOfBlock():wh.getQuantityOfColumn())*price;
	}
	
}
